/// @tags:
#include <bitset>
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

using ull = unsigned long long;
using std::bitset;

constexpr int maxn = 64;

void solve() {
  ull n;
  cin >> n;
  bitset<maxn> ans(0);
  while (ans.count() != 3) {
    if (n < 7) {
      cout << "-1\n";
      return;
    }
    bitset<maxn> bs(n);
    ans.reset();
    for (int i = maxn - 1; i >= 0; --i) {
      if (bs[i]) {
        ans[i] = 1;
      }
      if (ans.count() == 3) {
        break;
      }
    }
    n -= 1;
  }
  cout << ans.to_ullong() << '\n';
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B - Exactly Three Bits.in", "r", stdin);
  freopen("B - Exactly Three Bits.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
